package cn.com.self.security.user.dto.user;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;

import javax.persistence.Id;
import javax.validation.constraints.*;
import java.io.Serializable;

/**
 * <p>
 *
 * </p>
 *
 * @author liangwt
 * @since 2021-01-10
 */
@ApiModel(value = "会员信息类")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UMember implements Serializable {

    private static final long serialVersionUID=1L;
    /**
     * 会员id
     */
    @Id
    @ApiModelProperty(value = "会员id")
    private Long id;
    /**
     * 登录手机
     */
    @NotNull(message = "手机号不能为空")
    @NotBlank(message = "手机号不能为空")
    @Pattern(regexp ="^[1][3,4,5,6,7,8,9][0-9]{9}$", message = "手机号格式有误")
    @ApiModelProperty(value = "登录手机")
    private String phone;
    /**
     * 用户密码
     */
    @JsonIgnore
    @NotNull(message = "密码不能为空")
    @NotBlank(message = "密码不能为空")
    @ApiModelProperty(value = "用户密码")
    private String password;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public static UMember user2LoginUMember(UMember user) {
        return UMember.builder()
                .id(user.getId())
                .phone(user.phone)
                .password(user.getPassword())
                .build();
    }
}
